﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace NB.MGJ.Service
{
    public class EncryptHelper
    {
        /// <summary>
        /// 密码加密
        /// </summary>
        /// <param name="_password"></param>
        /// <param name="_salt"></param>
        /// <returns></returns>
        public string EncryptPassword(string _password, string _salt)
        {
            byte[] _PwdAndSaltBytes = Encoding.UTF8.GetBytes(_password + _salt);
            byte[] _HashBytes = new SHA256Managed().ComputeHash(_PwdAndSaltBytes);
            string _HashStr = Convert.ToBase64String(_HashBytes);
            return _HashStr;
        }
        /// <summary>
        /// md5
        /// </summary>
        /// <param name="encypStr"></param>
        /// <returns></returns>
        public string Md5(string encypStr)
        {
            byte[] signData = Encoding.GetEncoding("utf-8").GetBytes(encypStr);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] md5Data = md5.ComputeHash(signData);
            StringBuilder _Str = new StringBuilder();
            foreach (byte item in md5Data)
            {
                _Str.Append(item.ToString("x2"));
            }
            return _Str.ToString();
        }
    }
}
